//
// Created by zhouyi on 2019-11-29.
//

#ifndef TESTFFMPEG_VIDEOCHANNEL_H
#define TESTFFMPEG_VIDEOCHANNEL_H


#include <android/native_window.h>
#include "BaseChannel.h"
#include "JavaCallHelper.h"

extern "C" {
#include "libavcodec/avcodec.h"
#include "libavutil/rational.h"
}


class VideoChannel : public BaseChannel {
    friend void *asyncVideoPlay_t(void *args);

public:
    VideoChannel(int channelId, JavaCallHelper *helper, AVCodecContext *avCodecContext, const AVRational &base,
                 int fps);

    virtual ~VideoChannel();

    virtual void play();

    virtual void stop();

    virtual void decode();

    void setWindow(ANativeWindow *pWindow);

private:
    void _play();

private:
    int fps;
    pthread_t videoDecodeTask;
    pthread_mutex_t surfaceMutex;
    pthread_t videoPlayTask;
    bool isPlaying = false;
    ANativeWindow *window = nullptr;

    void onDraw(uint8_t *dst_data[4], int dst_linesSize[4], int width, int height);
};


#endif //TESTFFMPEG_VIDEOCHANNEL_H
